package com.umeox.watch.prayertime.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.provider.Settings
import com.umeox.moto.common.log.Logger
import com.umeox.watch.moto.dataservice.constants.Constants
import com.umeox.watch.prayertime.base.BaseApp

/**
 * Created by Rambo 2022/9/21
 * Describe:
 */
class PrayerSettingReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
        val action = intent?.action
        Logger.i("PrayerSettingReceiver action=$action")
        if(action == Constants.ACTION_UNBIND){
            val cancelIntent = Intent(AlarmReceiver.ACTION_CANCEL_ALARM)
            cancelIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES or Intent.FLAG_RECEIVER_FOREGROUND)
            BaseApp.getInstance().sendBroadcast(cancelIntent)
            return
        }
        if (action == Constants.ACTION_LOCATION_SUCCESS) {
            val lat = intent.getStringExtra("LAT")
            val long = intent.getStringExtra("LONG")
            Logger.e("lat=$lat,long=$long")
            if (!lat.equals("-999") && !long.equals("-999")) {
                Settings.Global.putString(context?.contentResolver,"LAT", lat)
                Settings.Global.putString(context?.contentResolver,"LONG", long)
            }
        }
        BaseApp.getInstance().schedulePrayerTimeAlarm()
    }
}